<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增专家评分')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-scoring-add" >
        <!--        <p>123</p>-->
        <!--        <p>[[${expertId}]]</p>-->


        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table">

            </table>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('system:items:edit')}]];
    var firstLevelCategoryDatas = [[${@dict.getType('sys_pf_first')}]];
    var scoringMethodDatas = [[${@dict.getType('sys_pf_dafenxs')}]];
    var isObjectiveDatas = [[${@dict.getType('sys_pf_iskg')}]];
    var editFlag = [[${@permission.hasPermi('system:items:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:items:remove')}]];

    var prefix = ctx + "system/scoring"
    var prefix1 = ctx + "system/items";
    $("#form-scoring-add").validate({
        focusCleanup: true
    });



    $(function() {
        var options = {
            url: prefix1 + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix1 + "/edit/{id}",
            removeUrl: prefix1 + "/remove",
            exportUrl: prefix + "/export",
            modalName: "评分项配置",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showPageGo: true,
            onEditableSave: onEditableSave,
            columns: [{
                checkbox: true
            },
                {
                    field: 'itemId',
                    title: '评分项ID',
                    visible: false
                },
                {
                    field: 'firstLevelCategory',
                    title: '一级分类',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(firstLevelCategoryDatas, value);
                    }
                },
                {
                    field: 'secondLevelCategory',
                    title: '二级分类'
                },
                {
                    field: 'itemName',
                    title: '评分项名称'
                },
                {
                    field: 'scoringMethod',
                    title: '打分形式',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(scoringMethodDatas, value);
                    }
                },
                {
                    field: 'scoreConfig',
                    title: '分值配置',
                },
                {
                    field: 'weight',
                    title: '权重'
                },
                {
                    field: 'isObjective',
                    title: '是否客观分',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isObjectiveDatas, value);
                    }
                },
                {
                    field: 'itemBz',
                    title: '指标评分标准'
                },
                {
                    title: '操作评分',
                    field: 'scoreSet',
                    width: '50px',
                    editable : true
                    //     {
                    //     type : 'text',
                    //     title : '请设置分值',
                    //     emptytext : "不可为空",
                    //     validate : function(value) {
                    //         if (value.length == 0) {
                    //             return '不能为空';
                    //         }
                    //     }
                    //
                    // }
                },
                {
                    title: '评分意见',
                    field: 'scoreYj',
                    editable : {
                        type : 'text',
                        title : '请填写分值意见',
                        emptytext : "不可为空",
                        validate : function(value) {
                            if (value.length == 0) {
                                return '不能为空';
                            }
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.itemId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.itemId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    function submitHandler() {
        var data = $("#" + table.options.id).bootstrapTable('getData');
        console.log(JSON.stringify(data));
        for (let i = 0; i < data.length; i++) {
            if(data[i].scoreSet === undefined || data[i].scoreSet === ''){
                alert("请对评分项最后一列进行评分！")
                return;
            }
        }
        if ($.validate.form()) {
            //$.operate.save(prefix + "/add", $('#form-scoring-add').serialize());
            $.operate.post(prefix + "/add", {'itemId':[[${expertId}]],'dataList': JSON.stringify(data)});
        }
    }
    function onEditableSave (field, row, rowIndex, oldValue, $el) {
        //alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue);
        //是否符合
        if(row.scoringMethod == '1'){
            var scoreSet = row.scoreSet;
            if(!(scoreSet === '是' || scoreSet === '否')){
                row[field] = undefined;
            }
        }
        //等级设置
        if(row.scoringMethod == '3'){
            var scoreSet = row.scoreSet;
            if(!(scoreSet === 'A' || scoreSet === 'B' || scoreSet === 'C' || scoreSet === 'D')){
                row[field] = undefined;
            }
        }
    }
</script>
</body>
</html>